package fr.labri.macchiato.core.model;

import fr.labri.macchiato.core.technical.FrameworkException;
import fr.labri.macchiato.core.technical.MObservable;

/**
 * 
 * @author Matthieu FOUCAULT
 * @TODO: javadoc
 * 
 */
abstract class AbstractProduct extends MObservable implements Product {

	private static final String ERROR_NULL_NAME = "Un produit doit avoir un nom";
	private static final int DEFAULT_QUANTITY = 1;

	private String name;
	private int quantity;

	public AbstractProduct() {
		super();
		setQuantity(DEFAULT_QUANTITY);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (name == null || name.trim().isEmpty())
			throw new FrameworkException(ERROR_NULL_NAME);
		this.name = name;

		notifyObservers();
	}

	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;

		notifyObservers();
	}

}
